package chapter02

object Test09_Fibonaqi {
  def main(args: Array[String]): Unit = {
    //1 1 2 3 5 8 f(n) = f(n-1)+f(n-2)
    //计算前n项的数列的数和前n项的和 计算第n项的值
    def f(n:Int):Int={
      if(n==1||n==2) 1 else f(n-1)+f(n-2)
    }
    def sum(n:Int):Int={
      var he = 0
      for(i<-1 to n){
        he += f(i)
        println(f(i))
      }
      he
    }
    println(sum(5))
  }
}
